﻿using System;
using System.Collections.Generic;
using System.Text;
using HAVNet.Core.String;


namespace HAVNet.Intros.AST
{
    //delegate int Fzz<T, U>(T t, U u)
    //    where T : new()                   |_______ constraints..
    //    where U : IComparable, new();     |

    public enum FixedConstraint
    { 
        _,
        STRUCT,
        CLASS,
        STRING,
        OBJECT,
    }

    public class ASTTypeConstraintList : List<ASTTypeConstraint>
    {
        public override string ToString()
        {
            return Strings.joinobjs(" ", this);
        }
    }

    public class ASTTypeConstraint : ASTNode
    {
        public string                       name        = "";
        public bool                         hasNewConstraint{ get; set; }   // tiene new()
        public FixedConstraint              fixedConstraint { get; set; }   // struct, class o nada..
        public readonly ASTTypeNames        typeNames   = new ASTTypeNames ();

        public override string ToString()
        {
            var items   = new List<string>();

            if (fixedConstraint == FixedConstraint.CLASS)
                items.Add("class" );

            if (fixedConstraint == FixedConstraint.STRUCT)
                items.Add("struct");

            if (fixedConstraint == FixedConstraint.STRING)  //?
                items.Add("string");

            if (fixedConstraint == FixedConstraint.OBJECT)  //?
                items.Add("object");

            items.Add(typeNames.ToString());

            if (hasNewConstraint)
                items.Add("new ()");

            return string.Format (
                "where {0} : {1}",
                name,
                Strings.joinobjs (", ", items)
            );
        }
    }
}
